package com.cqc.jdk8.Jio;

import java.io.File;
import java.io.IOException;

/**
 * @author cui
 * @date 2023/6/14 22:55
 * @description
 **/
public class RenameFileTest {

//    public static void main(String[] args) throws IOException {
//        String filePath = "E:\\Java\\余胜军springsecurity+jwt+oauth2.0入门到精通视频教程\\视频\\";
//        File dirFile = new File(filePath);
//        File[] files = dirFile.listFiles();
//        for (File file : files) {
//            String name = file.getName();
//            int index1 = name.indexOf(".");
//            int index2 = name.lastIndexOf("(");
//            int index3 = name.lastIndexOf(".");
//            String newName = name.substring(index1 + 1, index2) + name.substring(index3);
//            File newFile = new File(filePath + newName);
//            if (file.exists() && !newFile.exists()) {
//                file.renameTo(newFile);
//            }
//        }
//    }


    public static void main(String[] args) throws IOException {
        String filePath = "E:\\Java\\余胜军springsecurity+jwt+oauth2.0入门到精通视频教程\\视频\\";
        File dirFile = new File(filePath);
        File[] files = dirFile.listFiles();
        for (File file : files) {
            String name = file.getName();
            int index1 = name.indexOf(".");
            int index2 = name.indexOf("-");
            int index3 = name.lastIndexOf(".");
            String newName = name.substring(0, index1) + name.substring(index2+1);
            File newFile = new File(filePath + newName);
            if (file.exists() && !newFile.exists()) {
                file.renameTo(newFile);
            }
        }
    }
}
